package com.hundsun.s3.platform.backstage.action.report;

import com.hundsun.jresplus.common.util.StringUtil;
import com.hundsun.s3.common.dto.PageBean;

import com.hundsun.s3.common.dto.Performence;
import com.hundsun.s3.platform.backstage.common.util.ChartUtils;
import com.hundsun.s3.platform.service.PerformenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

/**
 * com.hundsun.s3.platform.backstage.action.report
 *
 * @Description:
 * @Author: yangjun23614
 * @Date: Created in 9:59 2018/3/6
 * V1.0 9:59 2018/3/6
 */
@Controller
@RequestMapping("/back/performence")
public class PerformenceAction {

    static Logger logger = Logger.getLogger(PerformenceAction.class.getName());

    @Autowired
    private PerformenceService performenceService;

    /**
     * @Description: 通过月份查绩效
     * @param: [int, int, String]
     * @return:  
     * @Author: yangjun23614
     * @Date: 14:03 2018/3/6
     * V1.0 
     */
    @RequestMapping("/performenceQryByMonth.json")
    public @ResponseBody Map<String,Object> performenceQryByMonth(int pageSize, int pageNo){
        PageBean pageBean = new PageBean();
        pageBean.setPNoPSize(pageNo,pageSize);
        Map<String,Object> map;
        int thisYearMonth = ChartUtils.getThisYearAndMonth();
        map = performenceService.performenceQryByMonth(Integer.toString(thisYearMonth),pageBean);
        Map<String,Object> rs = new HashMap<String, Object>();
        rs.put("rows",(List<Performence>)(map.get("list")));
        rs.put("total",((PageBean)map.get("page")).getCount());
        return rs;
    }

    /**
     * @Description: 查询byid
     * @param: 
     * @return:  
     * @Author: yangjun23614
     * @Date: 14:50 2018/3/9
     * V1.0 
     */
    @RequestMapping("/performenceQryBySId.json")
    public @ResponseBody Map<String,Object> performenceQryBySId(String pageSize, String pageNo, String staff_id,
                                                    String performence_start_time, String performence_end_time){
        PageBean pageBean = new PageBean();
        if(StringUtil.isEmpty(pageNo)){
            pageNo = "1";
        }
        if(StringUtil.isEmpty(pageSize)){
            pageSize = "10";
        }
        pageBean.setPNoPSize(Integer.parseInt(pageNo),Integer.parseInt(pageSize));
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("performence_start_time",performence_start_time);
        params.put("performence_end_time",performence_end_time);
        Map<String,Object> map;
        if (StringUtil.isNotEmpty(staff_id)) {
            params.put("staff_id",staff_id);
            params.put("first_record",pageBean.getStart());
            params.put("last_record",pageBean.getEnd());
            map = performenceService.performenceQryByParams(params,"400024");
            pageBean.setCount(performenceService.performenceCountQryByParams(params,"400026"));
        } else {
            pageBean.setCount(performenceService.performenceCountQryByParams(params,"400027"));
            params.put("first_record",pageBean.getStart());
            params.put("last_record",pageBean.getEnd());
            map = performenceService.performenceQryByParams(params,"400025");
        }
        Map<String,Object> rs = new HashMap<String,Object>();
        rs.put("rows",(List<Performence>)(map.get("list")));
        rs.put("total",pageBean.getCount());
        return rs;
    }

}